package code.D1214;

/**
 * author : yeswater
 * date : 2023/12/14
 * 
 * 买卖股票的最佳时机T
 * 
 */

public class T121 {
    public int maxProfit(int[] prices) {
        int cost = Integer.MAX_VALUE, profit = 0;
        for (int price: prices) {
            cost = Math.min(cost, price); // 最低成本
            profit = Math.max(profit, price - cost); // 最高利润
        }
        return profit;
    }
}
